import scrapy
import re

class StocksSpider(scrapy.Spider):
    name = 'stocks'
    # allowed_domains = ['baidu.com']
    start_urls = ['http://www.itcast.cn/channel/teacher.shtml']

    def parse(self,response):#解析页面
        list = response.xpath("//div[@class='li_txt']")
        for li in list:
            item = {}
            item['name'] = li.xpath(".//h3/text()").extract()[0]
            item['title'] = li.xpath(".//h4/text()").extract_first()
            print(item)

    # def parse_stock(self,response):
    #     infoDict = {}
    #     stockInfo = response.css('.txtl')
    #     name = stockInfo.css('.qphox').extract()[0]
    #     keyList = stockInfo.css('dt').extract()
    #     valueList = stockInfo.css('dd').extract()
    #     for i in range(len(keyList)):
    #         key = re.findall(r'>.*</dt>',keyList[i])[0][1:-5]
    #         try:
    #             val = re.findall(r'\d+\.?.*</dd>',valueList[i])[0][0:-5]
    #         except:
    #             val = '--'
    #         infoDict[key] = val
    #     infoDict.update(
    #         {'股票名称':re.findall('\s.*\(',name)[0].split()[0] + re.findall('\>.*<',name)[0][1:-1]})
    #     yield infoDict
